package com.abeir.bilibili.convert;

import java.io.File;
import java.nio.file.Path;
import java.util.Optional;

public class TitleScanner implements Scanner {

    private final String filename;

    public TitleScanner(String filename){
        this.filename = filename;
    }

    @Override
    public Optional<File> target(Path dir) {
        File[] files = dir.toFile().listFiles((d, name) -> name.equals(filename));
        if(files == null || files.length == 0){
            return Optional.empty();
        }
        if(files.length > 1){
            throw new IllegalArgumentException("Multiple " + this.filename + " files were discovered.");
        }
        return Optional.of(files[0]);
    }
}
